package distriKub;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.awt.Cursor;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.ListModel;
import javax.swing.SwingConstants;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class RegPlayerPanel extends javax.swing.JFrame {
	
	Myself boundPlayer;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel RegPanel;
	private JLabel lbl_infoPanelMain;
	private JLabel lbl_PlayerID;
	private JLabel lbl_Resitered;
	private JList registeredPlayers;
	private JButton registerPlayerButton;
	private JPasswordField regPasswordTextField;
	private JLabel jLabel2;
	private JLabel jLabel1;
	private JTextField regUserNameTextField;
	private JTextField regPlayerIdTextField;

	/**
	* Auto-generated main method to display this JFrame
	*/
	
	public RegPlayerPanel() {
		super();
		initGUI();
	}
	
Action registerPlayerClicked = new AbstractAction("") {
	
		private static final long serialVersionUID = 1L;

		@Override
		public void actionPerformed(ActionEvent e) {
			System.out.println("===> RegPlayerPanel.java ===> Register Player was clicked !");
			String screenName =  regUserNameTextField.getText();
			String userId = regPlayerIdTextField.getText();
			char[] password = regPasswordTextField.getPassword();
			boundPlayer.registerUser(userId, screenName, new String(password));
		}
	};
	
	public void bindToPlayer(Myself thePlayer){
		this.boundPlayer = thePlayer;
	}
	
	public void updateRegisteredUsernamesInGUI(String[] userNames){
		ListModel userNamesListModel = new DefaultComboBoxModel(userNames);
		registeredPlayers.setModel(userNamesListModel);
		registeredPlayers.setSelectedIndex(0);
	}
		
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
			BorderLayout thisLayout = new BorderLayout();
			getContentPane().setLayout(thisLayout);
			BufferedImage image = null;
	        try {
	            image = ImageIO.read(this.getClass().getResource("/distriKub\\images\\appicon.png"));
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        this.setIconImage(image);
	        this.setTitle("DistriKub - Player Registration");
			{
				RegPanel = new JPanel();
				getContentPane().add(RegPanel, BorderLayout.CENTER);
				GroupLayout RegPanelLayout = new GroupLayout((JComponent)RegPanel);
				RegPanel.setLayout(RegPanelLayout);
				RegPanel.setBackground(new java.awt.Color(185,255,185));
				RegPanel.setPreferredSize(new java.awt.Dimension(538, 222));
				RegPanel.setSize(538, 280);
				{
					lbl_infoPanelMain = new JLabel();
					lbl_infoPanelMain.setText("Player Registration");
					lbl_infoPanelMain.setFont(new java.awt.Font("Tahoma",1,26));
					lbl_infoPanelMain.setForeground(new java.awt.Color(0,0,255));
					lbl_infoPanelMain.setName("lbl_infoPanelMain");
				}
				{
					lbl_PlayerID = new JLabel();
					lbl_PlayerID.setText("Player ID");
					lbl_PlayerID.setFont(new java.awt.Font("Tahoma",1,14));
					lbl_PlayerID.setForeground(new java.awt.Color(0,128,255));
				}
				{
					regUserNameTextField = new JTextField();
					regUserNameTextField.setFont(new java.awt.Font("Tahoma",0,12));
					regUserNameTextField.setForeground(new java.awt.Color(0,0,255));
					regUserNameTextField.setHorizontalAlignment(SwingConstants.CENTER);
				}
				{
					jLabel1 = new JLabel();
					jLabel1.setText("User Name");
					jLabel1.setFont(new java.awt.Font("Tahoma",1,14));
					jLabel1.setForeground(new java.awt.Color(0,128,192));
				}
				{
					regPlayerIdTextField = new JTextField();
					regPlayerIdTextField.setForeground(new java.awt.Color(0,0,255));
					regPlayerIdTextField.setFont(new java.awt.Font("Tahoma",0,12));
					regPlayerIdTextField.setHorizontalAlignment(SwingConstants.CENTER);
				}
				{
					ListModel registeredPlayersModel = 
						new DefaultComboBoxModel(
								new String[] { "Item One", "Item Two" });
					registeredPlayers = new JList();
					registeredPlayers.setModel(registeredPlayersModel);
					registeredPlayers.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				}
				{
					lbl_Resitered = new JLabel();
					lbl_Resitered.setText("Other Players");
					lbl_Resitered.setFont(new java.awt.Font("Tahoma",1,14));
					lbl_Resitered.setForeground(new java.awt.Color(128,0,255));
				}
				{
					registerPlayerButton = new JButton();
					registerPlayerButton.setEnabled(true);
					registerPlayerButton.setAction(registerPlayerClicked);
					registerPlayerButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("distriKub/images/done.jpg")));
					registerPlayerButton.setBorder(new LineBorder(new java.awt.Color(0,0,0),2,true));
					registerPlayerButton.setToolTipText("Register Player");
					registerPlayerButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
				}
				{
					jLabel2 = new JLabel();
					jLabel2.setText("Password");
					jLabel2.setFont(new java.awt.Font("Tahoma",1,14));
					jLabel2.setForeground(new java.awt.Color(0,128,192));
				}
				{
					regPasswordTextField = new JPasswordField();
					regPasswordTextField.setForeground(new java.awt.Color(0,0,255));
					regPasswordTextField.setFont(new java.awt.Font("Tahoma",0,12));
					regPasswordTextField.setHorizontalAlignment(SwingConstants.CENTER);
				}
				RegPanelLayout.setHorizontalGroup(RegPanelLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(RegPanelLayout.createParallelGroup()
					    .addComponent(regUserNameTextField, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE)
					    .addComponent(regPasswordTextField, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE)
					    .addComponent(regPlayerIdTextField, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE)
					    .addGroup(RegPanelLayout.createSequentialGroup()
					        .addGap(26)
					        .addGroup(RegPanelLayout.createParallelGroup()
					            .addGroup(GroupLayout.Alignment.LEADING, RegPanelLayout.createSequentialGroup()
					                .addComponent(lbl_PlayerID, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE)
					                .addGap(18))
					            .addGroup(RegPanelLayout.createSequentialGroup()
					                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					                .addGroup(RegPanelLayout.createParallelGroup()
					                    .addGroup(GroupLayout.Alignment.LEADING, RegPanelLayout.createSequentialGroup()
					                        .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
					                        .addGap(18))
					                    .addComponent(jLabel1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 93, GroupLayout.PREFERRED_SIZE))))
					        .addGap(6)))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(RegPanelLayout.createParallelGroup()
					    .addGroup(GroupLayout.Alignment.LEADING, RegPanelLayout.createSequentialGroup()
					        .addGap(0, 0, Short.MAX_VALUE)
					        .addComponent(lbl_infoPanelMain, GroupLayout.PREFERRED_SIZE, 258, GroupLayout.PREFERRED_SIZE)
					        .addGap(122))
					    .addGroup(GroupLayout.Alignment.LEADING, RegPanelLayout.createSequentialGroup()
					        .addGap(40)
					        .addGroup(RegPanelLayout.createParallelGroup()
					            .addGroup(RegPanelLayout.createSequentialGroup()
					                .addGap(0, 0, Short.MAX_VALUE)
					                .addComponent(registeredPlayers, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE))
					            .addGroup(GroupLayout.Alignment.LEADING, RegPanelLayout.createSequentialGroup()
					                .addGap(0, 7, Short.MAX_VALUE)
					                .addComponent(lbl_Resitered, GroupLayout.PREFERRED_SIZE, 108, GroupLayout.PREFERRED_SIZE)))
					        .addGap(97)
					        .addComponent(registerPlayerButton, GroupLayout.PREFERRED_SIZE, 128, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap());
				RegPanelLayout.setVerticalGroup(RegPanelLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(lbl_infoPanelMain, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(40)
					.addGroup(RegPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(lbl_PlayerID, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					    .addComponent(lbl_Resitered, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE))
					.addGroup(RegPanelLayout.createParallelGroup()
					    .addGroup(GroupLayout.Alignment.LEADING, RegPanelLayout.createSequentialGroup()
					        .addComponent(regPlayerIdTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					        .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addComponent(regUserNameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 1, Short.MAX_VALUE)
					        .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addComponent(regPasswordTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					    .addGroup(RegPanelLayout.createSequentialGroup()
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addGroup(RegPanelLayout.createParallelGroup()
					            .addGroup(RegPanelLayout.createSequentialGroup()
					                .addComponent(registeredPlayers, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE))
					            .addGroup(RegPanelLayout.createSequentialGroup()
					                .addComponent(registerPlayerButton, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE)))
					        .addGap(0, 0, Short.MAX_VALUE)))
					.addGap(7));
			}
			pack();
			this.setSize(554, 270);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
